package dao

import (
	"zhou_gin_api/app/models"
	"zhou_gin_api/datasource"
)

type UserDao struct {
	BaseDao
}

func NewUserDao() *UserDao {
	return &UserDao{
		BaseDao: BaseDao{
			gormdb: datasource.GetGormDb(),
		},
	}
}

func (dao *UserDao) First(id uint) (*models.UserModel, error) {
	var userModel models.UserModel
	userModel.ID = id

	err := dao.gormdb.First(&userModel).Error

	return &userModel, err
}

func (dao *UserDao) Gets(userWhere *models.UserModel) []models.UserModel {
	var users []models.UserModel

	dao.gormdb.Where(userWhere).Find(&users)

	return users
}
